<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <button>取消定时器</button>

    <script>

        /* 
            取消定时器需要基于setTimeout的返回值
         */
        const btnObj = document.querySelector("button")
       const timeOut1 =  setTimeout(function(){
            console.log("3秒后执行函数")
        },3000)

        btnObj.onclick = function(){
            clearTimeout(timeOut1)
        }
    </script>
</body>
</html>